package com.lds.offer.entity;

import jdk.nashorn.internal.objects.annotations.Setter;

/**
 * @description:
 * @author: lds
 * @create: 2022-10-09 14:59
 **/
public class BinaryTreeNode {
    public int val;
    public BinaryTreeNode left;
    public BinaryTreeNode right;
    public BinaryTreeNode() {}
    BinaryTreeNode(int val) { this.val = val; }
    BinaryTreeNode(int val, BinaryTreeNode left, BinaryTreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    /**
     *    初始化树结构
     *            5
     *         /    \
     *        4     8
     *      /      / \
     *     11    13  4
     *    / \       / \
     *   7  2      5   1
     */
    public static BinaryTreeNode init() {
        BinaryTreeNode fourLeft1 = new BinaryTreeNode(7);
        BinaryTreeNode fourRight1 = new BinaryTreeNode(2);
        BinaryTreeNode threeLeft1 = new BinaryTreeNode(11,fourLeft1,fourRight1);

        BinaryTreeNode fourLeft2 = new BinaryTreeNode(5);
        BinaryTreeNode fourRight2 = new BinaryTreeNode(1);
        BinaryTreeNode threeRight3 = new BinaryTreeNode(4,fourLeft2,fourRight2);
        BinaryTreeNode threeLeft2 = new BinaryTreeNode(13);

        BinaryTreeNode twoLeft1 = new BinaryTreeNode(4,threeLeft1,null);
        BinaryTreeNode twoRight1 = new BinaryTreeNode(8,threeLeft2,threeRight3);

        BinaryTreeNode root = new BinaryTreeNode(5,twoLeft1,twoRight1);

        return root;
    }


    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public BinaryTreeNode getLeft() {
        return left;
    }

    public void setLeft(BinaryTreeNode left) {
        this.left = left;
    }

    public BinaryTreeNode getRight() {
        return right;
    }

    public void setRight(BinaryTreeNode right) {
        this.right = right;
    }
}
